﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "TemporaryDimensionHandler.h"
#include <QObject>


class QLineEdit;
class QEvent;

namespace gcmp
{
    class IUiView;
    class IGraphicsNodeGroup;

    class LinearTemporaryDimensionHandler final : public TemporaryDimensionHandler
    {
        Q_OBJECT

    public:
        explicit LinearTemporaryDimensionHandler(IUiView* pUIView);
        virtual ~LinearTemporaryDimensionHandler(void);

        virtual bool event(QEvent* pEvent) override;
        virtual bool eventFilter(QObject* obj, QEvent* pEvent) override;

    public:

        // IElementEditHelper接口:
        // 获取临时标注Greps
        virtual OwnerPtr<IGraphicsNodeGroup> GenerateGraphics(const ITemporaryDimensionContext* pCtx) override;

        // 键盘唤醒条件
        virtual bool WakeOn(int nKeyChar, bool isCtrlPressed = false, bool isAltPressed = false, bool isShiftPressed = false) override;

        // 
        virtual bool UpdateConfig(const ITemporaryDimensionContext* pCtx) override;

    public:
        bool SetLengthEnabled(bool val) { m_enableLength = val; return true; }
        bool SetAngleEnabled(bool val) { m_enableAngle = val; return true; }

    protected:
        // 显示输入框控件，并设置输入类型和显示初值
        virtual void ShowInputWidget(InputState InputState, bool isTabShift = false, bool isOverrideValue = false, std::wstring inputValue = L"") override;

    private slots:
        virtual void OnEditorReturnPressed() override;
        void OnEditorTabPressed();

    private:
        bool IsLengthEnabled() const { return m_enableLength; }
        bool IsAngleEnabled() const { return m_enableAngle; }

    private:
        bool m_enableLength;
        bool m_enableAngle;
    };

}


